package com.woniu.service.impl;

import com.woniu.dao.ICapitalChannelDao;
import com.woniu.entity.CapitalChannelEntity;
import com.woniu.entity.CapitalChannelExportVO;
import com.woniu.entity.CapitalChannelSearchVO;
import com.woniu.entity.SysAdminVO;
import com.woniu.service.ICapitalChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @description: 用于处理资金渠道请求的service接口的实现类
 * @author Dante
 * @date: 2022/9/20 19:31
 */

@Service
public class ICapitalChannelServiceImpl implements ICapitalChannelService {
    @Autowired
    ICapitalChannelDao capitalChannelDao;

    @Override
    public List<CapitalChannelEntity> findAll() {
        return capitalChannelDao.findAll();
    }

    @Override
    public List<CapitalChannelEntity> selectChannels(CapitalChannelExportVO data) {
        return capitalChannelDao.selectChannels(data);
    }

    @Override
    public List<CapitalChannelEntity> searchWithLimits(CapitalChannelSearchVO data) {
        return capitalChannelDao.searchWithLimits(data);
    }

    @Override
    public Boolean addCapitalChannel(CapitalChannelEntity data) {
        Integer count = capitalChannelDao.searchOneCapitalChannel(data.getChannelName());
        if (count>1){
            return false;
        }else{
            Integer maxCapitalChannelId = capitalChannelDao.getMaxCapitalChannelId();
            if (Objects.nonNull(maxCapitalChannelId)){
                data.setId(maxCapitalChannelId+1);
            }

            Integer add = capitalChannelDao.addCapitalChannel(data);
            if (add==0){
                return false;
            }
            return true;
        }

    }

    @Override
    public SysAdminVO findCurrentUser(String userName) {
        return capitalChannelDao.findCurrentUser(userName);
    }

    @Override
    public Boolean updateChannelStatus(Integer channelId) {
        Integer updateRes = capitalChannelDao.updateChannelStatus(channelId);
        if (Objects.nonNull(updateRes)){
            if (updateRes>0){
                return true;
            }
        }
        return false;
    }

    @Override
    public CapitalChannelEntity checkChannelInfo(Integer channelId) {
        return capitalChannelDao.checkChannelInfo(channelId);
    }

    @Override
    public Boolean updateCapitalChannel(CapitalChannelEntity data) {
        Integer count = capitalChannelDao.searchOneCapitalChannel(data.getChannelName());
        if (count>1){
            return false;
        }else{
            Integer add = capitalChannelDao.updateCapitalChannel(data);
            if (add==0){
                return false;
            }
            return true;
        }
    }

    @Override
    public List<SysAdminVO> getAllUserInfo() {
        return capitalChannelDao.getAllUserInfo();
    }

    @Override
    public Boolean banChannel(Integer channelId) {
        Integer updateResult = capitalChannelDao.banChannel(channelId);
        if(updateResult>0){
            return true;
        }
        return false;
    }

}
